package com.zcx.qshop.adapter;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.helper.view.rebound.ReboundLayout;
import com.zcx.helper.view.rebound.ReboundListView;
import com.zcx.helper.widget.AppReboundAdapter;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.conn.JsonTypelistAsyGet;

import java.util.List;

/**
 * Created by Administrator on 2015/8/17 0017.
 */
public class TwoListAdapter extends AppReboundAdapter<JsonTypelistAsyGet.TypeOne> {

    private LayoutInflater layoutInflater;

    public TwoListAdapter(Context context, ReboundListView reboundListView, List<JsonTypelistAsyGet.TypeOne> objects) {

        super(context, reboundListView, objects);

        layoutInflater = ((Activity)context).getLayoutInflater();

    }

    @Override
    public ReboundLayout getReboundLayout(int i, ReboundLayout reboundLayout, ViewGroup viewGroup) {

        JsonTypelistAsyGet.TypeOne typeOne = getItem(i);

        ViewHolder viewHolder;  

        if(reboundLayout == null){

            reboundLayout = (ReboundLayout) BoundViewHelper.boundView(viewHolder = new ViewHolder(), QSApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_two_list, null)));

            reboundLayout.setTag(viewHolder);

        }else{

            viewHolder = (ViewHolder) reboundLayout.getTag();

        }

        viewHolder.img.setImageURI(Uri.parse(typeOne.typepic));

        viewHolder.name.setText(typeOne.typetitle);

        viewHolder.content.setText(typeOne.typeinfo);

        return reboundLayout;

    }

    private class ViewHolder{

        @BoundView(R.id.item_two_list_img) private SimpleDraweeView img;

        @BoundView(R.id.item_two_list_name) private TextView name;

        @BoundView(R.id.item_two_list_content) private TextView content;

        @BoundView(R.id.item_two_list_unit) private TextView unit;

    }

}
